/*
获取一些公共数据，不需要token验证
包括注册
*/
const express = require('express')
const pool = require('../../mysql/mysql')
const router = express.Router()

//获取书籍列表并且分页
router.post('/booktown',(req,res)=>{
  let page = req.body.page
    //通过cid 查询数据库  并且实现分页
  /** page     offset    pagesize
   *  1        0         10
   *  2        10        10
   *  3        20        10
   *  .....
   *  n        (n-1)*10  10
   */
  let pagesize = 10;
  let offset = (page-1)* pagesize
  let off = offset+10
  let sql = 'select * from e_book limit ?,?'
  pool.query(sql,[offset,off],(error,result)=>{
    if(error) throw error
    console.log(result.length)
    if(result.length>0){
      res.send({code:200,message:'ok',data:result})
    }
  })
})


module.exports = router 